package org.jeecg.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    @Bean(name = "threadPool")
    public ThreadPoolExecutor threadPoolTaskExecutor() {
                int corePoolSize = 30; // 核心线程数
                int maximumPoolSize = 100; // 最大线程数
                long keepAliveTime = 1; // 非核心线程的闲置超时时间
                TimeUnit unit = TimeUnit.MINUTES; // keepAliveTime的时间单位
                ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(300); // 任务队列

                return new ThreadPoolExecutor(
                        corePoolSize,
                        maximumPoolSize,
                        keepAliveTime,
                        unit,
                        workQueue
                );
    }
}
